package hlhj.fhp.supreme.activitys

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.widget.LinearLayout
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.chad.library.adapter.base.entity.MultiItemEntity
import fhp.hlhj.giantfold.utils.LogUtil
import hlhj.fhp.supreme.BaseAty
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.javabean.JiePanCommentBean
import hlhj.fhp.supreme.javabean.JiePanDetailMultiBean
import kotlinx.android.synthetic.main.activity_jie_pan_text_detail_aty.*
import java.util.ArrayList

class JiePanTextDetailAty : BaseAty() {
    override fun getContentId(): Int = R.layout.activity_jie_pan_text_detail_aty
    private lateinit var adp:BaseMultiItemQuickAdapter<MultiItemEntity,BaseViewHolder>
    private lateinit var commentAdp:BaseQuickAdapter<String,BaseViewHolder>
    private val  datas=ArrayList<MultiItemEntity>()
    override fun initView() {
        /*头部*/
        val headBean = JiePanDetailMultiBean(1)
        /*评论*/
        val commentBean = JiePanCommentBean(2)
        commentBean.comment.add("1")
        commentBean.comment.add("1")
        commentBean.comment.add("1")
        commentBean.comment.add("1")
        commentAdp=object :BaseQuickAdapter<String,BaseViewHolder>(R.layout.option_comment_item,commentBean.comment){
            override fun convert(helper: BaseViewHolder?, item: String?) {

            }
        }
        datas.add(headBean)
        datas.add(commentBean)
        adp=object :BaseMultiItemQuickAdapter<MultiItemEntity,BaseViewHolder>(datas){
            init {
                addItemType(1,R.layout.jiepan_detail_text_head)
                addItemType(2,R.layout.jiepan_comment_listview)
            }
            override fun convert(helper: BaseViewHolder?, item: MultiItemEntity?) {
                LogUtil.log("类型为${helper?.itemViewType}")
                when(helper?.itemViewType){
                    1->{

                    }
                    2->{
                        val recyclerView = helper?.getView<RecyclerView>(R.id.recyclerview)
                        LogUtil.log((recyclerView==null).toString())
                        recyclerView.adapter=commentAdp
                        recyclerView.layoutManager=LinearLayoutManager(this@JiePanTextDetailAty,LinearLayoutManager.VERTICAL,false)
                    }
                }
            }
        }

        recyclerview.adapter=adp
        recyclerview.layoutManager=LinearLayoutManager(this,LinearLayout.VERTICAL,false)
    }

    override fun initListener() {

        btExit.setOnClickListener { finish()}
    }
}
